<?php

namespace App\Modules\LuckDraw\Models;

use Illuminate\Database\Eloquent\Model;

class ManualAwardModel extends Model {
    protected $table = "luck_draw_manual_award";

    //获取手动发送的奖品
    public static function get(int $luckId, int $userId, int $limit): ?array {
        $curTime =  date('Y-m-d H:i:s');
        return self::query()->where('luck_id', $luckId)
            ->where('user_id', $userId)
            ->where('status', 0)
            ->where('deleted', 0)
            ->where('timeout', ">", $curTime)
            ->limit($limit)
            ->get()
            ->all();
    }

    public static function setHasBeenSentByIds(int $drawId, array $ids): int {
        return self::query()->whereIn('id', $ids)
            ->update(['draw_id' => $drawId, 'status'=>1]);
    }

    public static function setHasBeenDeleted(int $id): int {
        return self::query()->where('id', $id)
            ->update(['deleted'=>1]);
    }
}